<?php
require("libraries/student.php");
class Ageinfo extends Student{
    public function __construct(){
        parent::__construct();
		$this->load->model("model_ageinfo");
		$this->load->helper('mail_helper');
    }
	public function index(){
		$data['data'] = "";
		$data['act'] = 3;
		$config['base_url'] = base_url().'admin/ageinfo/index/';
		$config['total_rows'] = $this->model_ageinfo->count_all();
		$config['per_page'] = 10;
		$config['uri_segment'] = 4;
		$config['next_link'] = "Next";
		$config['prev_link'] = "Previous";
		$config['cur_tag_open'] = "<span class='curpage'>";
		$config['cur_tag_close'] = "</span>";
		$this->load->library("pagination");
		$this->pagination->initialize($config); 
		$start = $this->uri->segment(4);
		$data['title'] = "Agency confirm";
		$data['listall'] = $this->model_ageinfo->listall($config['per_page'],$start);
		$data['template'] = "ageinfo/list";
		$this->load->view("layout",$data);
	}
	public function views(){
		$data['data'] = "";
		$id = $this->uri->segment(4);
		$data['title'] = "View info update of agency confirm";
		$data['result'] = $this->model_ageinfo->getdata($id);
		if($data['result'] == NULL){
			redirect(base_url()."admin/index");
		}
		//$this->debug($data['listall']);
		$data['template'] = "ageinfo/views";
		$this->load->view("layout",$data);
	}
	public function active(){
		$id = $this->uri->segment(4);
		$status = $this->uri->segment(5);
		if($status != 1 and $status != 0){die("Not found");}
		$result = $this->model_ageinfo->getdata($id);
		if($result == NULL){ die("Not found");}
		$user = $this->model_ageinfo->getuser($result['agencyid']);
		if($user == NULL){die("This agency is not exits");}
		//$this->debug($user);
		$db = array(
			"sheep_name" => $result['name'],
			"sheep_name_rewrite" => $result['rewrite'],
			"sheep_ltinerary" => $result['adress'],
			"sheep_phone" => $result['phone'],
			"sheep_email" => $result['email'],
			"sheep_site" => $result['website'],
			"sheep_order" => $result['order'],
			"sheep_price" => $result['pricepro'],
			"sheep_price_old" => $result['pricenol'],
			"sheep_keys" => $result['keywords'],
			"sheep_des" => $result['description'],
			"sheep_status" => $result['status'],
			"sheep_tour1" => $result['duration1'],
			"sheep_tour2" => $result['duration2'],
			"sheep_tour3" => $result['duration3'],
			"sheep_tour4" => $result['duration4'],
			"sheep_tour5" => $result['duration5'],
			"sheep_fact" => $result['sheetlink'],
			"sheep_menu" => $result['menulink'],
			"sheep_drink" => $result['drinklink'],
			"sheep_videos" => $result['youtlink'],
			"sheep_info" => $result['shortinfo'],
			"sheep_include" => $result['include'],
			"sheep_1day" => $result['oneday'],
			"sheep_2day" => $result['twoday'],
			"sheep_3day" => $result['threeday'],
			"sheep_4day" => $result['fourday'],
			"sheep_5day" => $result['fiveday']
		);
		if($result['logo'] != NULL){
			$db['sheep_logo'] = $result['logo'];
		}
		if($result['slideimg'] != NULL){
			$db['sheep_image'] = $result['slideimg'];
		}
		if($result['logo'] != NULL){
			$db['sheep_image_thumb'] = $result['imgthumb'];
		}
		$agency = array("active"=>$status);
		$this->sendmail($user['email'],"");
		$this->model_ageinfo->updatecrui($result['cruiseid'],$db);
		$this->model_ageinfo->update($id,$agency);
		redirect(base_url()."admin/ageinfo");
	}
	public function del(){
		$id = $this->uri->segment(4);
		$data = $this->model_ageinfo->getdata($id);
		if($data == NULL){ redirect(base_url()."admin/ageinfo");}
		/*@unlink("uploads/sheep/logo/".$data['logo']);
		@unlink("uploads/sheep/logo/".$data['slideimg']);
		@unlink("uploads/sheep/logo/".$data['imgthumb']);
		@unlink("uploads/sheep/logo/thumb/".$data['logo']);
		@unlink("uploads/sheep/logo/thumb/".$data['slideimg']);
		@unlink("uploads/sheep/logo/thumbs/".$data['imgthumb']);*/
		$this->model_ageinfo->del($id);
		redirect(base_url()."admin/ageinfo");
	}
	public function sendmail($email,$file=""){
		   $mesnger = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
				<html>
				<head>
				<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
				<style type="text/css">
					body{font:12px Verdana, Geneva, sans-serif;}
				</style>
				</head>
				<body>
					<h3 style="font-size:16px;">YOUR INFOMARTION HAS BEEN UPDATED</h3>
					<p>You have a message from bestcruiseshalong.com! We apologize for the inconvenience, your information has been updated. thank you for using our service</p>
					<p>&nbsp;</p>
					<p>Head Office</p>
					<p>Units 08&09A, 3rd Floor, <br />International Centre, 17 Ngo Quyen Str., <br /> Hoan Kiem Dist., Hanoi, Vietnam <br />
					   Tel: +84 4 39392929 Fax: +84 4 39368338
					</p>
				<br/>
            ';
		  $mesnger.= "<body></html>";
		  send_mail_helper($email,'Confirm for your partners',htmlspecialchars_decode($mesnger),$file);
	}
}
?>